//
//  AYuEmoticonPageView.swift
//  SHWeibo3
//
//  Created by 余伟康 on 16/7/30.
//  Copyright © 2016年 wangce. All rights reserved.
//

import UIKit

// cell 的可重用标识符
private let AYuEmoticonPageViewCellId = "AYuEmoticonPageViewCellId"

class AYuEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = RandomColor()
        // 注册cell
        registerClass(AYuEmoticonPageViewCell.self, forCellWithReuseIdentifier: AYuEmoticonPageViewCellId)
        // 获取layout
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        // 设置item
        layout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        // 设置垂直和水平间距
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        // 滚动方向
        layout.scrollDirection = .Horizontal
        dataSource = self
    }
}

extension AYuEmoticonPageView:UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return AYuEmoticonTools.shardTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return AYuEmoticonTools.shardTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(AYuEmoticonPageViewCellId, forIndexPath: indexPath) as! AYuEmoticonPageViewCell
//        cell.indexPath = indexPath
        cell.emoticons = AYuEmoticonTools.shardTools.allEmoticons[indexPath.section][indexPath.item]
        return cell
    }
}



